﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Manager;
using Model;
using ExtAspNet;
using Manager.CustomerHelper;
namespace HealthSystem.sysAdmin
{
    public partial class SchoolMerge_Add :BasePage
    {
        HW_SchoolManager manager = new HW_SchoolManager();
        public override ModuleType Module
        {
            get
            {
                return ModuleType.SchoolManager;
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                choosebt.OnClientClick = Window1.GetSaveStateReference(orgcode.ClientID, TextBox2.ClientID)
                  + Window1.GetShowReference("~/ChooseOrg.aspx");
                Button2.OnClientClick = Window1.GetSaveStateReference(districtname.ClientID, districtid.ClientID)
                  + Window1.GetShowReference("~/sysadmin/dischoose.aspx");
                btnClose.OnClientClick = ActiveWindow.GetConfirmHidePostBackReference();
            }
        }
        protected void Save_Click(object sender, EventArgs e)
        {
            string pdistrictId = districtid.Text;
            if (string.IsNullOrEmpty(pdistrictId))
            {
                Alert.Show("区域不能为空");
                return;
            }
            if (string.IsNullOrEmpty(orgcode.Text))
            {
                Alert.Show("体检机构不能为空");
                return;
            }
            HW_DistrictManager dismanager = new HW_DistrictManager();
            string cityid = dismanager.GetById(pdistrictId).ParentDistrictCode;
            HW_School org = new HW_School();
            //org.SchoollCode = pdistrictId + DateTime.Now.Year.ToString().Substring(1, DateTime.Now.Year.ToString().Length - 1) + DateTime.Now.Minute.ToString().PadLeft(2, '0') + DateTime.Now.Millisecond.ToString().PadLeft(3, '0') + newUserId.ToString().PadLeft(5, '0');
            org.SchoollCode = pdistrictId + DateTime.Now.Year.ToString().Substring(1, DateTime.Now.Year.ToString().Length - 1) + DateTime.Now.Minute.ToString().PadLeft(2, '0') + DateTime.Now.Millisecond.ToString().PadLeft(3, '0') + "11111";
            org.DistrictCode = districtid.Text;
            org.CityId = cityid;
            org.Name = name.Text;
            org.SchoolType = stype.SelectedText;
            org.OrgCode = orgcode.Text;
            org.Address = Address.Text;
            org.LinkMan = LinkMan.Text;
            org.OfficePhone = OfficePhone.Text;
            org.MobilePhone = MobilePhone.Text;
            org.Email = Email.Text;
            org.Permit = permitcheck.Checked;
            string merges=Request["mergeid"] as string;
            string[] mergeArry=merges.Trim(',').Split(',');
            try
            {
                HW_SchoolMergeLogManager mergerManager = new HW_SchoolMergeLogManager();
                bool permit = permitcheck.Checked;
                mergerManager.SchoolMerge(org, mergeArry, schoolcheck.Checked,permit);
                Alert.Show("学校合并成功！");
                PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
            }
            catch(Exception ex)
            {
                Alert.Show(ex.Message);
            }
        }
        private void Gird2Bind()
        {

        }
    }
}